package domfarr.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import javax.persistence.Embeddable;
import javax.persistence.OneToMany;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
 * Entity for ContactDetails
 * 
 * @author Dominic Farr
 */
@Embeddable
public final class ContactDetails implements Serializable {

	private static final long serialVersionUID = 1L;

	@OneToMany
	private List<Address> addresses;

	private String email;
	private String phoneNumber;

	public ContactDetails() {
		this.addresses = Collections.emptyList();
	}

	public ContactDetails(final List<Address> addresses, final String email,
			final String phoneNumer) {
		this.addresses = new ArrayList<Address>(addresses);
		this.email = email;
		this.phoneNumber = phoneNumer;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(final String email) {
		this.email = email;
	}

	public String getPhoneNumber() {
		return phoneNumber;
	}

	public void setPhoneNumber(final String phoneNumber) {
		this.phoneNumber = phoneNumber;
	}

	public List<Address> getAddresses() {
		return Collections.unmodifiableList(this.addresses);
	}

	public void setAddresses(List<Address> addresses) {
		this.addresses = new ArrayList<Address>(addresses);
	}

	@Override
	public String toString() {
		return ToStringBuilder.reflectionToString(this,
				ToStringStyle.SHORT_PREFIX_STYLE);
	}

	@Override
	public int hashCode() {
		return HashCodeBuilder.reflectionHashCode(this);
	}

	@Override
	public boolean equals(Object rhs) {
		return EqualsBuilder.reflectionEquals(this, rhs);
	}
}
